package com.goldenKey.admin.controller;

import com.goldenKey.common.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.goldenKey.common.pojo.po.Book;
import com.goldenKey.admin.service.IBookService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/02/02
 */
@RestController
@RequestMapping("/book")
public class BookController {

	@Autowired
	private IBookService bookService;

	/**
	 * 新增数据
	 * @param book
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Book book) {
		bookService.save(book);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param bookId
	 * @return
	 */
	@DeleteMapping("/deleteById/{bookId}")
	public R<Void> deleteById(@PathVariable("bookId") Integer bookId) {
		bookService.removeById(bookId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param book
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Book book) {
		bookService.updateById(book);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param bookId
	 * @return
	 */
	@GetMapping("/getById/{bookId}")
	public R<Book> getById(@PathVariable("bookId") Integer bookId) {
		Book book = bookService.getById(bookId);
		return R.ok(book);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Book>> list() {
		List<Book> bookList = bookService.list();
		return R.ok(bookList);
	}

}